package studio.banner.reference.util;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

import studio.banner.reference.entity.UserLogin;
import studio.banner.reference.service.UserInfoService;
import studio.banner.reference.service.UserLoginService;

public class ShiroUtil {
	@Autowired
	private UserLoginService userLoginService;
	
	public static String getMd5(String pwd,String username) {
		
	        // 加密算法MD5
	        // salt盐 username + salt
	        // 迭代次数
	        String md5Pwd = new SimpleHash("MD5", pwd,
	                ByteSource.Util.bytes(username + "salt"), 2).toHex();
	        return md5Pwd;
	    }
/*
 * 验证用户密码进行更新查询
 */
	public  Integer resultUpdate(UserLogin userlogin) {
		String password=userLoginService.findUserLogin(userlogin.getUsername());
		if(password!=null) {
			String md5Pwd=getMd5(userlogin.getPassword(),userlogin.getUsername());
			if(password.equals(md5Pwd)) {
				return 1;
			}
		}
		return 0;
	}
public static void main(String[] args) {
	System.out.println(getMd5("123465","001"));
}
	} 

